#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "linksettings.h"
#include <QFileDialog>
#include <QStandardPaths>
#include <QMessageBox>
#include <QCloseEvent>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    slt_task_done(QJsonObject(), true, "");

    auto ls = LinkSettings::Inst();

    if (!ls->getDebugEnabled()) {
        //ui->groupBox_config->hide();
    }

    connect(this, &MainWindow::destroyed, [](){
        exit(0);
    });
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::slt_clientLogin(QString client_id, QString server)
{
    this->setWindowTitle("ClientID: " + client_id);
    //ui->label_client_id->setText(client_id);
    ui->label_server->setText(server);
}

void MainWindow::slt_statusChange(QString msg)
{
    qDebug() << msg;
    //ui->label_server_status->setText("[" + msg + "]");
}

void MainWindow::slt_task_start(QJsonObject task)
{
    ui->label_task_id->setText(task["id"].toString());
    //ui->label_task_type->setText(task["type"].toString());
    //ui->label_task_src->setText(task["src_path"].toString());
    //ui->label_task_dst->setText(task["dst_path"].toString());
    ui->label_task_status->setText("working");
}

void MainWindow::slt_task_done(QJsonObject task, bool result, QString msg)
{
    Q_UNUSED(task);
    Q_UNUSED(result);
    Q_UNUSED(msg);
    ui->label_task_id->setText("[empty]");
    //ui->label_task_type->setText("");
    //ui->label_task_src->setText("");
    //ui->label_task_dst->setText("");
    ui->label_task_status->setText("");
}

void MainWindow::closeEvent(QCloseEvent *event)
{
    if (QApplication::keyboardModifiers () != Qt::ControlModifier) {
        event->ignore();
    }
}

